package at.sysarch.gui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

import at.sysarch.model.Line;

/**
 * 
 * @author Andi
 *
 * TableModel to display results from Sink to a JTable.
 */
public class LineTableModel implements TableModel {

	private List<Line> _lines;
	
	public LineTableModel() {
		
		_lines = new ArrayList<Line>();
	}
	
	public void addLine(Line line) {
		
		_lines.add(line);
	}
	
	public void addLines(List<Line> lines) {
		
		_lines.addAll(lines);
	}
	
	public void clear() {
		
		_lines.clear();
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {

		switch (columnIndex) {
		
			case 0:
				return String.class;
			case 1:
				return Integer.class;
			default:
				return null;
		}
	}

	@Override
	public int getColumnCount() {

		return 2;
	}

	@Override
	public String getColumnName(int columnIndex) {

		switch (columnIndex) {
		
			case 0:
				return "Line";
			case 1:
				return "Index";
			default:
				return null;
		}
	}

	@Override
	public int getRowCount() {

		return _lines.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {

		switch (columnIndex) {
		
			case 0:
				return _lines.get(rowIndex).getData();
			case 1:
				return _lines.get(rowIndex).getIndex();
			default:
				return null;
		}
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {

		return false;
	}
	


	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {		
	}
	
	@Override
	public void addTableModelListener(TableModelListener l) {		
	}
	
	@Override
	public void removeTableModelListener(TableModelListener l) {		
	}

}
